package day11;

import java.io.*;

/**
 * @author Xiao
 * @date 2021/8/2
 */
public class Test09 {
    /**
     * 9. 预习马上要学的Day11第20、21、22三个视频，完成对任意文件的复制操作。例如：将当前项目下的a.txt文件复制到d盘下
     */
    public static void main(String[] args) throws IOException {
        //字节缓冲流拷贝：一次读写1个字节数组
        //bufferedIOStream();
        //字节流拷贝：一次读写1个字节
        FileInputStream fis = new FileInputStream("homework\\sr\\day11\\stu.txt");
        FileOutputStream fos = new FileOutputStream("homework\\sr\\day11\\stuCopy.txt");
        int read;
        while ((read = fis.read()) != -1) {
            fos.write(read);
        }
        fis.close();
        fos.close();
    }

    /**字节缓冲流拷贝文件：一次读写1个字节数组*/
    private static void bufferedIOStream() throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
                "homework\\stu.txt"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
                "homework\\stuCopy.txt"));
        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }
        bis.close();
        bos.close();
    }
}
